home *** CD-ROM | disk | FTP | other *** search
/ PC Media 3 / PC MEDIA CD03.iso / share / udos / off_line / off_line.c next >
Encoding:
C/C++ Source or Header  |  1992-10-03  |  2.8 KB  |  82 lines

  1. /* off-line.cpp    Reads the PCBoard DIR files and changes the date to OFF-LINE */
  2.  
  3. #include <conio.h>
  4. #include <process.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. struct
  9.    {
  10.    char rec1[23];
  11.    char rec2[57];
  12.    } rec4;
  13.  
  14. void main(int argc,char* argv[])
  15.    {
  16.                                  /* Define variables */
  17.    unsigned end=99999;
  18.    unsigned dirext=1;            /* the '01' in directory name DL01 */
  19.    char  dirfile[12+1];
  20.    char  buffer[80];
  21.            
  22.    FILE *infile;                 /* define files */
  23.    FILE *outfile;
  24.                                  /* command line arg */
  25.  
  26.    clrscr();
  27.       
  28.    if (argc == 2) /* if command line parm is given, process that file */
  29.       {
  30.       strcpy(dirfile,(char *)argv[1]);
  31.       end=2;      /* process one file, (< 2) */
  32.       }     
  33.    for(dirext=1; dirext < end; dirext++)    /* main processing loop      */
  34.       {     
  35.       unlink("DIR.$$$");                    /* delete temp file if exists */
  36.       if (argc == 1)     
  37.          sprintf(dirfile,"%s%02d","DIR",dirext); /* build dirfile("DIR01") */
  38.       
  39.       if (rename(dirfile,"DIR.$$$") != 0)   /* rename real file to temp file */
  40.          {
  41.          printf("%s%s\n","Can't process file: ",dirfile);
  42.          exit(1);
  43.          }
  44.       if((infile=fopen("DIR.$$$","r"))==NULL)   /* open input file */
  45.          {
  46.          printf("Error opening input file");
  47.          exit(1);
  48.          }
  49.       if((outfile=fopen(dirfile,"w+"))==NULL)   /* open output file */
  50.          {
  51.          printf("Error opening output file");
  52.          exit(1);
  53.          }
  54.       memset(buffer,'\0',sizeof(buffer));       /* clear buffer */
  55.       fgets(buffer,80,infile);                  /* get first record */
  56.       do
  57.          {
  58.          strcpy(rec4.rec1,buffer);
  59.          if(buffer[23] >= '0' && buffer[23] <= '9' &&     /* if date in col */
  60.              buffer[24] >= '0' && buffer[24] <= '9' &&     /* 24 thru 31     */
  61.             buffer[25] == '-'                      &&
  62.              buffer[26] >= '0' && buffer[26] <= '9' &&
  63.             buffer[27] >= '0' && buffer[27] <= '9' &&
  64.              buffer[28] == '-'                      &&
  65.             buffer[29] >= '0' && buffer[29] <= '9' &&
  66.             buffer[30] >= '0' && buffer[30] <= '9'   )
  67.             {
  68.             strncpy(rec4.rec2,"OFF-LINE",8);
  69.             strcpy(buffer,rec4.rec1);
  70.             }
  71.          printf(buffer);                    /* show user the line */
  72.          fputs(buffer,outfile);             /* write the record */
  73.          memset(buffer,'\0',sizeof(buffer));
  74.          fgets(buffer,80,infile);           /* get next record  */
  75.          } while(!feof(infile));            /* end of do{} loop */
  76.            
  77.       fclose(infile);
  78.       fclose(outfile);
  79.       unlink("DIR.$$$");                    /* delete old file */
  80.       }
  81.    }
  82.